<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEmployeesTable extends Migration
{
    /**
     * Run the migrations.
     * 员工表
     * @return void
     */
    public function up()
    {
        Schema::create('employees', function (Blueprint $table) {
            $table->increments('id');
            $table->string('mark')->comment('员工编码');
            $table->string('name')->comment('员工姓名');
            $table->string('id_type')->comment('证件类型')->default('身份证')->nullable();
            $table->string('id_no')->comment('证件号码')->nullable();
            $table->string('id_start_time')->comment('证件生效日期')->nullable();
            $table->string('id_end_time')->comment('证件失效日期')->nullable();
            $table->string('birthday')->comment('出生日期')->nullable();
            $table->string('phone',30)->comment('电话号码')->nullable();
            $table->string('email')->comment('邮箱')->nullable();
            $table->string('education')->comment('学历')->nullable();
            $table->string('college')->comment('毕业院校')->nullable();
            $table->string('major')->comment('专业')->nullable();
            $table->string('age')->comment('年龄')->nullable();
            $table->char('sex',1)->comment('性别 1男 0女')->nullable();
            $table->string('residence')->comment('户籍所在地')->nullable();
            $table->text('address')->comment('家庭住址')->nullable();
            $table->string('nation')->comment('民族')->nullable();
            $table->text('bank_name')->comment('开户行')->nullable();
            $table->string('account')->comment('银行账号')->nullable();
            $table->Integer('organization_id')->unsigned()->comment('所属组织')->nullable();
            $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('set null');
            $table->unsignedInteger('department_id')->unsigned()->comment('所属部门')->nullable();
            $table->foreign('department_id')->references('id')->on('departments')->onDelete('set null');
            $table->Integer('post_id')->comment('岗位')->unsigned()->nullable();
            $table->foreign('post_id')->references('id')->on('posts')->onDelete('set null');
            $table->Integer('skill_id')->comment('职级')->unsigned()->nullable();
            $table->foreign('skill_id')->references('id')->on('skills')->onDelete('set null');
            $table->string('emergency_contact')->comment('紧急联系人')->nullable();
            $table->string('emergency_phone',20)->comment('紧急联系人电话')->nullable();
            $table->string('emergency_relation')->comment('紧急联系人关系')->nullable();
            $table->timestamp('entry_time')->comment('入职时间')->nullable();
            $table->string('creator')->comment('创建人')->default('admin');
            $table->string('disable')->comment('禁用人')->default('admin');
            $table->timestamp('disable_time')->comment('禁用时间')->useCurrent();
            $table->boolean('data_state')->comment('数据状态 0未审核 1已审核')->default(0);
            $table->boolean('disabled_state')->comment('禁用状态 0反禁用-启用 1禁用')->default(0);
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['id_no','deleted_at']);
        });

        Schema::create('employee_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('employee_id')->unsigned()->comment('员工id')->nullable();
            $table->foreign('employee_id')->on('employees')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('employee_files');
        Schema::dropIfExists('employees');
    }
}
